const {
  override,
  addDecoratorsLegacy,
  addPostcssPlugins
} = require("customize-cra");
const path = require("path");
const px2rem = require("postcss-px2rem-exclude");

const styleLoader = () => config => {
  const loaders = config.module.rules.find(rule => Array.isArray(rule.oneOf))
    .oneOf;

  // 修改less-loader 对 css-modules的配置
  loaders[loaders.length - 3].use[1].options.modules = true;
  loaders[loaders.length - 3].use[1].options.localIdentName = "[local]";
  return config;
};

module.exports = override(
  addDecoratorsLegacy(),
  styleLoader(),
  addPostcssPlugins([
    px2rem({ remUnit: 75 / 2, exclude: /node_modules/i })
  ]),
  config => {
    config.resolve.alias = {
      "@": path.resolve(__dirname, "src")
    };
    return config;
  }
);
